import {fetch} from '@/utils/fetch'
import {comment, user} from '../fragment'

export const createForAnswer = async ({ answerId, isNeedRedo = false, data }) => {
  let res = await fetch({
    query: `mutation ($data: JSON!) {
      createCommentForAnswer (input: {
        answerId: ${answerId},
        isNeedRedo: ${isNeedRedo},
        data: $data
      }) {
        ${comment}
        userInfo {
          ${user}
        }
      }
    }`,
    variables: {
      data
    }
  })
  return res.data.createCommentForAnswer
}

export const bulkCreateForTask = async ({ taskId, userIds, data, isNeedRedo = false }) => {
  let res = await fetch({
    query: `mutation ($userIds: [Int!]!, $data: JSON!, $isNeedRedo: Boolean) {
      createBulkCommentsForTask (
        taskId: ${taskId},
        userIds: $userIds,
        data: $data,
        isNeedRedo: $isNeedRedo
      ) {
        id
      }
    }`,
    variables: {
      data,
      userIds,
      isNeedRedo
    }
  })
  return res.data.createBulkCommentsForTask
}
